#include "Comm.hpp"
#include "Fifo.hpp"

//Client端：获取共享内存、写入数据
int main()
{
    //创建通信key值
    key_t key = CreateShmKeyOrDie();
    cout << "Client key : " << ToHex(key) << endl;

    //获取共享内存
    int shmid = GetShm(key, default_size);
    cout << "Client shmid : " << shmid << endl;

    //挂载共享内存
    //获取地址时必须确定指针类型，指针类型之间不会发生隐式类型转换需要进行强转
    char* addr = (char*)ShmAttach(shmid);

    //以写方式打开管道文件
    Sync sync;
    sync.OpenWriteOrDie();

    //写入数据
    for(char i = 'A'; i <= 'Z'; i++)
    {
        addr[i - 'A'] = i;

        sleep(1);

        sync.Wakeup();//唤醒读端
    }

    //解绑共享内存
    ShmDettach(addr);

    return 0;
}